package edu.neu.cloud_factory.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import edu.neu.cloud_factory.entity.po.Schedule;
import edu.neu.cloud_factory.dao.ScheduleMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 排产计划 服务实现类
 * </p>
 *
 * @author halozhy
 * @since 2021-07-15
 */
@Service
public class ScheduleService extends ServiceImpl<ScheduleMapper, Schedule> implements IService<Schedule> {

    @Autowired
    ScheduleMapper scheduleMapper;

    public List<Schedule> selectStartingScheduleListByDIdAndTime(Long dId, Date nowTime) {
        // 检索出排产计划里面设备编号为此设备，且 开始时间<= 现在 && 现在<= 结束时间 的计划
        QueryWrapper<Schedule> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("s_device_id",dId);
        queryWrapper.le("s_start_time", nowTime);
        queryWrapper.ge("s_end_time", nowTime);
        return scheduleMapper.selectList(queryWrapper);
    }

    public List<Schedule> selectScheduleListByDId(Long dId) {
        QueryWrapper<Schedule> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("s_device_id",dId);
        return scheduleMapper.selectList(queryWrapper);
    }
}
